
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using Andromeda.Global.Business;
using Andromeda.Global.Data.Db;
using Andromeda.Global.Common;
using ForgeIt.Dal.dbo.Validator;

  
namespace ForgeIt.Dal.dbo.Stub
{
	internal abstract class DBCustomerStub : dboSchema
	{
		#region private fields

		/// <summary>
		/// (fieldname, datatype, ischangeable(!isidentity), isinsertable(!isidentity), isforeignkey, foreigntable
		/// </summary>

		protected readonly DbField foIdCustomer = new DbField("IdCustomer", DbType.Int32, true, true, false, false, false, "");

		protected readonly DbField foIdEntity = new DbField("IdEntity", DbType.Int32, false, false, true, true, true, "Entity");

		protected readonly DbField foIdCountry = new DbField("IdCountry", DbType.Int32, false, false, true, true, false, "");

		protected readonly DbField foFIN = new DbField("FIN", DbType.String, false, false, true, true, false, "");

		protected readonly DbField foFoundingDate = new DbField("FoundingDate", DbType.DateTime, false, false, true, true, false, "");

  
        #region local cache - Foreign Keys

        protected DBEntity localIdEntity;
  

        #endregion local cache - Foreign Keys


        #endregion private fields

        #region constructors

        protected DBCustomerStub()
		{
		}

		protected DBCustomerStub(bool ignorethis, int foIdCountry, string foFIN, System.DateTime foFoundingDate, Int32 foIdEntity)
		{

			this.foIdCountry.Value = foIdCountry;

			this.foFIN.Value = foFIN;

			this.foFoundingDate.Value = foFoundingDate;

			this.foIdEntity.Value = foIdEntity;

		}
	
		#endregion constructors
    
		#region public properties
		
		public override DbConnector CleanEntity
		{
			get { return new DBCustomer(); }
		}


		public int IdCustomer
		{
			get { return ObjectConverter.ToInt32(foIdCustomer.Value); }
		}

		public int IdEntity
		{
			get { return ObjectConverter.ToInt32(foIdEntity.Value); }
			set { foIdEntity.Value = value; }
		}

		public int IdCountry
		{
			get { return ObjectConverter.ToInt32(foIdCountry.Value); }
			set { foIdCountry.Value = value; }
		}

		public string FIN
		{
			get { return ObjectConverter.ToString(foFIN.Value); }
			set { foFIN.Value = value; }
		}

		public System.DateTime FoundingDate
		{
			get { return ObjectConverter.ToDateTime(foFoundingDate.Value); }
			set { foFoundingDate.Value = value; }
		}

  
		public override string TableName
		{
			get { return "Customer"; }
		}



        #region Foreign Keys
      
        /// <summary>
        /// Getter method for Object encapsulated view of foreign key
        /// </summary>
        public virtual DBEntity GetFK_IdEntity()
        {
          return localIdEntity ?? (localIdEntity = DBEntity.GetEntity(IdEntity));
        }
        /// <summary>
        /// Setter method for Object encapsulated view of foreign key
        /// </summary>        
        public virtual void SetFK_IdEntity(DBEntity paramIdEntity)
        {
          localIdEntity = paramIdEntity;
          IdEntity = paramIdEntity.IdEntity;
        }
      
        #endregion Foreign Keys


		    protected override ValidationModelBase Validator
		    {
			    get { return new DBCustomerValidator(); }
		    }
		#endregion public properties
    
		#region enumerator

		/// <summary>
		/// This enumerator contains a list of all the fields of the datasource
		/// </summary>
		public enum FieldNames
		{
			IdCustomer,
			IdEntity,
			IdCountry,
			FIN,
			FoundingDate,

		}

		#endregion enumerator
    
		#region generic field methods

		/// <summary>
		/// Validates if a given  field value is a DbNull
		/// </summary>
		/// <param name="fieldName">The field to validate</param>
		///<returns>true if is DbNull, false otherwise</returns>
		public bool IsDbNull(FieldNames fieldName)
		{
			switch (fieldName)
			{

				case FieldNames.IdCustomer: return (foIdCustomer.Value is DBNull);

				case FieldNames.IdEntity: return (foIdEntity.Value is DBNull);

				case FieldNames.IdCountry: return (foIdCountry.Value is DBNull);

				case FieldNames.FIN: return (foFIN.Value is DBNull);

				case FieldNames.FoundingDate: return (foFoundingDate.Value is DBNull);

			}

			throw new InvalidDataException();
		}

		/// <summary>
		/// Sets the given field value to DbNull
		/// </summary>
		/// <param name="fieldName">The field to set</param>
		public void SetDbNull(FieldNames fieldName)
		{
			switch (fieldName)
			{

				case FieldNames.IdCustomer:
					foIdCustomer.Value = DBNull.Value; break;

				case FieldNames.IdEntity:
					foIdEntity.Value = DBNull.Value; break;

				case FieldNames.IdCountry:
					foIdCountry.Value = DBNull.Value; break;

				case FieldNames.FIN:
					foFIN.Value = DBNull.Value; break;

				case FieldNames.FoundingDate:
					foFoundingDate.Value = DBNull.Value; break;

			}
		}
		
		#endregion generic field methods
    
        #region static factories

		/// <summary>
		/// Creates a new DB object that can be added to the database as a new row
		/// </summary>
		/// <returns>The instance of the DB Object</returns>
		public static DBCustomer NewRow
		{
			get { return new DBCustomer(); }
		}

		/// <summary>
		/// Returns multiple rows from the Datasource by a given set of WHERE clause fields, only includes fields where value != null
		/// </summary>
		/// <example>List of fields to filter by, null to ignore field (null = all).</example>
		/// <returns>A collection with the filtered results. </returns>
		internal static IEnumerable<DBCustomer> ListEntity(object foIdCustomer, object foIdEntity, object foIdCountry, object foFIN, object foFoundingDate)
		{
			DBCustomer helper = new DBCustomer();
			

			helper.foIdCustomer.Value = foIdCustomer;

			helper.foIdEntity.Value = foIdEntity;

			helper.foIdCountry.Value = foIdCountry;

			helper.foFIN.Value = foFIN;

			helper.foFoundingDate.Value = foFoundingDate;


			return helper.GetEntityInstancesList(helper.Fields.ToArray()).Cast<DBCustomer>();
        }

		/// <summary>
		/// Returns multiple rows from the Datasource by a given set of WHERE clause fields, only includes fields where value != null
		/// </summary>
		/// <example>List of fields to filter by, null to ignore field (null = all).</example>
		/// <returns>A collection with the filtered results. </returns>
		internal static IEnumerable<DBCustomer> ListEntity()
		{
			return new DBCustomer().GetEntityInstancesList(new DbField[0]).Cast<DBCustomer>();
        }

      		/// <summary>
		/// Returns a single row from the datasource by a given set of RUID strong-typed values
		/// </summary>
		/// <returns>The instance for this key or a new one if no match is found.</returns>
		internal static DBCustomer GetEntity(int foIdCustomer)
		{
			DBCustomer helper = new DBCustomer();

			helper.foIdCustomer.Value = foIdCustomer;

			helper = helper.GetEntityInstance(helper.Ruid) as DBCustomer;
			
			return helper;
		}


        /// <summary>
        /// Returns multiple rows from the Datasource that referentiate a specific foreign object 
        /// </summary>
        /// <param name="foIdEntity">The <see cref="DBEntity"/> object to filter by.</param>
        /// <returns>A collection with the filtered results.</returns>
        public static  IEnumerable<DBCustomer> ListEntityIdEntity(DBEntity foIdEntity)
        {
          DBCustomer helper = new DBCustomer();

          helper.foIdEntity.Value = foIdEntity.IdEntity;

          return helper.GetEntityInstancesList(helper.foIdEntity).Cast<DBCustomer>();
        }

		#endregion static factories
	}
}